package com.weyoung.app.controller;

import com.weyoung.app.common.convention.result.Result;
import com.weyoung.app.pojo.dto.req.EmergencyContactAddReqDTO;
import com.weyoung.app.pojo.dto.resp.EmergencyContactRespDTO;
import com.weyoung.app.pojo.entity.EmergencyContacts;
import com.weyoung.app.service.EmergencyContactsService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 紧急联系人控制器
 */
@RestController
@RequestMapping("/emergency-contacts")
@CrossOrigin
@RequiredArgsConstructor
public class EmergencyContactsController {

    private final EmergencyContactsService emergencyContactsService;

    /**
     * 添加紧急联系人
     *
     * @param requestParam 紧急联系人信息
     * @return 是否添加成功
     */
    @PostMapping
    public Result<Void> addEmergencyContact(@RequestBody EmergencyContactAddReqDTO requestParam) {
        emergencyContactsService.addEmergencyContact(requestParam);
        return Result.success();
    }

    /**
     * 获取紧急联系人列表
     *
     * @return 紧急联系人列表
     */
    @GetMapping
    public Result<List<EmergencyContactRespDTO>> getEmergencyContacts() {
        List<EmergencyContactRespDTO> responseDtos = emergencyContactsService.getList();
        return Result.success(responseDtos);
    }

    /**
     *  删除紧急联系人
     *
     * @param id id
     * @return 列表
     */
    @DeleteMapping
    public Result<List<EmergencyContactRespDTO>> deleteById(@RequestParam("id") Integer id){
        return Result.success(emergencyContactsService.deleteById(id));
    }
}    